package br.gov.cemaden.library.model.pcds;

import br.gov.cemaden.library.model.BaseEntity;
import br.gov.cemaden.library.model.Municipio;
import br.gov.cemaden.library.model.Posicao;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.validation.constraints.Size;

/**
 *
 * @author alan
 */
@Entity
@Table(name = "pcds_estacao", schema = "pcds")
@SequenceGenerator(name = "sequence", sequenceName = "pcds.pcds_estacao_sequence", schema = "pcds")
@NamedQueries({
    @NamedQuery(name = "Estacao.findAll", query = "SELECT e FROM Estacao e ORDER BY e.idEstacao"),
    @NamedQuery(name = "Estacao.findByRede", query = "SELECT e FROM Estacao e WHERE e.rede = :rede"),
    @NamedQuery(name = "Estacao.countByRede", query = "SELECT COUNT(*) FROM Estacao e WHERE e.rede = :rede"),
    @NamedQuery(name = "Estacao.findByMunicipio", query = "SELECT e FROM Estacao e WHERE e.municipio = :municipio"),
    @NamedQuery(name = "Estacao.findByTipo", query = "SELECT e FROM Estacao e WHERE e.tipoEstacao = :tipoEstacao"),
})
public class Estacao implements Serializable, BaseEntity {
    
    @Id
    @GeneratedValue(generator = "sequence", strategy = GenerationType.AUTO)
    @Column(name="id_estacao", nullable = false, unique = true)    
    private Long idEstacao;
    
    @Size(max = 255)
    @Column(name = "codestacao")
    private String codEstacao;
    
    @Column(name="latitude")
    private Double latitude;
    
    @Column(name="longitude")
    private Double longitude;
    
    @Column(name="status")
    private Short status;
    
    @Size(max = 255)
    @Column(name = "nome")
    private String nome;
        
    @ManyToOne(optional = false)
    @JoinColumn(name="id_municipio", referencedColumnName = "id_municipio")
    private Municipio municipio;
    
    @ManyToOne(optional = false)
    @JoinColumn(name = "id_posicao", referencedColumnName = "id_posicao")
    private Posicao posicao;
        
    @ManyToOne(optional = false)
    @JoinColumn(name = "id_rede", referencedColumnName = "id_rede")
    private Rede rede;
    
    @ManyToOne(optional = false)
    @JoinColumn(name = "id_tipoestacao", referencedColumnName = "id_tipoestacao")
    private TipoEstacao tipoEstacao;    

    public Estacao() {
    }

    public Estacao(Long idEstacao) {
        this.idEstacao = idEstacao;
    }
    
    public Long getId() {
        return this.getIdEstacao();
    }     

    /**
     * @return the idEstacao
     */
    public Long getIdEstacao() {
        return idEstacao;
    }

    /**
     * @param idEstacao the idEstacao to set
     */
    public void setIdEstacao(Long idEstacao) {
        this.idEstacao = idEstacao;
    }

    /**
     * @return the codEstacao
     */
    public String getCodEstacao() {
        return codEstacao;
    }

    /**
     * @param codEstacao the codEstacao to set
     */
    public void setCodEstacao(String codEstacao) {
        this.codEstacao = codEstacao;
    }

    /**
     * @return the latitude
     */
    public Double getLatitude() {
        return latitude;
    }

    /**
     * @param latitude the latitude to set
     */
    public void setLatitude(Double latitude) {
        this.latitude = latitude;
    }

    /**
     * @return the longitude
     */
    public Double getLongitude() {
        return longitude;
    }

    /**
     * @param longitude the longitude to set
     */
    public void setLongitude(Double longitude) {
        this.longitude = longitude;
    }

    /**
     * @return the status
     */
    public Short getStatus() {
        return status;
    }

    /**
     * @param status the status to set
     */
    public void setStatus(Short status) {
        this.status = status;
    }

    /**
     * @return the nome
     */
    public String getNome() {
        return nome;
    }

    /**
     * @param nome the nome to set
     */
    public void setNome(String nome) {
        this.nome = nome;
    }         

    /**
     * @return the municipio
     */
    public Municipio getMunicipio() {
        return municipio;
    }

    /**
     * @param municipio the municipio to set
     */
    public void setMunicipio(Municipio municipio) {
        this.municipio = municipio;
    }

    /**
     * @return the posicao
     */
    public Posicao getPosicao() {
        return posicao;
    }

    /**
     * @param posicao the posicao to set
     */
    public void setPosicao(Posicao posicao) {
        this.posicao = posicao;
    }

    /**
     * @return the rede
     */
    public Rede getRede() {
        return rede;
    }

    /**
     * @param rede the rede to set
     */
    public void setRede(Rede rede) {
        this.rede = rede;
    }

    /**
     * @return the tipoEstacao
     */
    public TipoEstacao getTipoEstacao() {
        return tipoEstacao;
    }

    /**
     * @param tipoEstacao the tipoEstacao to set
     */
    public void setTipoEstacao(TipoEstacao tipoEstacao) {
        this.tipoEstacao = tipoEstacao;
    }
    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (getIdEstacao() != null ? getIdEstacao().hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Estacao)) {
            return false;
        }
        Estacao other = (Estacao) object;
        if ((this.getIdEstacao() == null && other.getIdEstacao() != null) || (this.getIdEstacao() != null && !this.idEstacao.equals(other.idEstacao))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "codigo:"+codEstacao;
        //return String.format("Estacao{ codigo:%s, nome:%s, longitute:%d, latitude:%d, Municipio:%i, Rede:%i }", getCodEstacao(), getNome(), getLongitude(), getLatitude(), getIdMunicipio(), getIdRede());
    }
    
}
